package com.panda.QQserver.service;

import com.panda.qqcommon.Message;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class MonitorIsOnline extends Thread {

    public boolean flag = true;
    public Message message=null;

    public void Monitor() throws IOException {
        if(ManageClientThreads.getHm().containsKey(message.getGetter())){
            ServerConnectClientThread thread = ManageClientThreads.getThread(message.getGetter());
            Socket socket = thread.getSocket();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
            objectOutputStream.writeObject(message);
            flag = false;
        }
    }


    @Override
    public void run() {
        while(flag){
            try {
                Thread.sleep(500);
                Monitor();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }


        }
    }
}
